#include("../../comm/ListHead.html")
<div class="layui-card">
    <table class="layui-hide" id="table_1" lay-filter="table_1"></table>

    <script type="text/html" id="table_1_bar_title">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm btn-edit" lay-event="InitSysCodeColumn">初始化字段</button>
            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-more="btn-del" lay-event="DelSysCodeColumn">删除</button>
            <button class="layui-btn layui-btn-sm layui-btn-warm" lay-event="ReloadCodeColumn">刷新</button>
            <button class="layui-btn layui-btn-sm" lay-event="CloseCodeColumn">关闭</button>
        </div>
    </script>
    <script type="text/html" id="TmpKey">
        <input type="checkbox" field="is_key" msg="设置主键" value="{{d.cc_id}}" lay-skin="primary"
               lay-filter="ChangeTag" {{ d.is_key ? 'checked' : '' }}>
    </script>

    <script type="text/html" id="TmpHidden">
        <input type="checkbox" field="f_hidden" msg="隐藏" value="{{d.cc_id}}" lay-skin="primary"
               lay-filter="ChangeTag" {{ d.f_hidden ? 'checked' : '' }}>
    </script>

    <script type="text/html" id="TmpShow">
        <input type="checkbox" field="f_show" msg="设置显示" value="{{d.cc_id}}" lay-skin="primary"
               lay-filter="ChangeTag" {{ d.f_show ? 'checked' : '' }}>
    </script>
    <script type="text/html" id="EditSelect">
        <input type="checkbox" field="f_select" msg="设置选择" value="{{d.cc_id}}" lay-skin="primary"
               lay-filter="ChangeTag" {{ d.f_select ? 'checked' : '' }}>
    </script>
    <script type="text/html" id="EditSwitch">
        <input type="checkbox" field="f_switch" msg="设置开关" value="{{d.cc_id}}" lay-skin="primary"
               lay-filter="ChangeTag" {{ d.f_switch ? 'checked' : '' }}>
    </script>
    <script type="text/html" id="EditImg">
        <input type="checkbox" field="f_img" msg="设置图片" value="{{d.cc_id}}" lay-skin="primary"
               lay-filter="ChangeTag" {{ d.f_img ? 'checked' : '' }}>
    </script>
    <script type="text/html" id="EditDate">
        <input type="checkbox" field="f_date" msg="设置日期" value="{{d.cc_id}}" lay-skin="primary"
               lay-filter="ChangeTag" {{ d.f_date ? 'checked' : '' }}>
    </script>
    <script type="text/html" id="EditIcon">
        <input type="checkbox" field="f_icon" msg="设置图标" value="{{d.cc_id}}" lay-skin="primary"
               lay-filter="ChangeTag" {{ d.f_icon ? 'checked' : '' }}>
    </script>
    <script type="text/html" id="EditNumber">
        <input type="checkbox" field="f_number" msg="设置数字" value="{{d.cc_id}}" lay-skin="primary"
               lay-filter="ChangeTag" {{ d.f_number ? 'checked' : '' }}>
    </script>
    <script type="text/html" id="EditColor">
        <input type="checkbox" field="f_color" msg="设置选色" value="{{d.cc_id}}" lay-skin="primary"
               lay-filter="ChangeTag" {{ d.f_color ? 'checked' : '' }}>
    </script>
    <script type="text/html" id="EditMore">
        <input type="checkbox" field="f_more" msg="设置多行" value="{{d.cc_id}}" lay-skin="primary"
               lay-filter="ChangeTag" {{ d.f_more ? 'checked' : '' }}>
    </script>
    <script type="text/html" id="EditAuto">
        <input type="checkbox" field="f_auto" msg="设置自增" value="{{d.cc_id}}" lay-skin="primary"
               lay-filter="ChangeTag" {{ d.f_auto ? 'checked' : '' }}>
    </script>
    <script type="text/html" id="EditReadonly">
        <input type="checkbox" field="f_readonly" msg="设置只读" value="{{d.cc_id}}" lay-skin="primary"
               lay-filter="ChangeTag" {{ d.f_readonly ? 'checked' : '' }}>
    </script>
    <script type="text/html" id="VerifyNull">
        <input type="checkbox" field="f_vnull" msg="验证不能为空" value="{{d.cc_id}}" lay-skin="primary"
               lay-filter="ChangeTag" {{ d.f_vnull ? 'checked' : '' }}>
    </script>
    <script type="text/html" id="VerifyNumber">
        <input type="checkbox" field="f_vnumber" msg="验证数字" value="{{d.cc_id}}" lay-skin="primary"
               lay-filter="ChangeTag" {{ d.f_vnumber ? 'checked' : '' }}>
    </script>

    <script type="text/html" id="VerifyEmail">
        <input type="checkbox" field="f_vemail" msg="验写邮箱" value="{{d.cc_id}}" lay-skin="primary"
               lay-filter="ChangeTag" {{ d.f_vemail ? 'checked' : '' }}>
    </script>
    <script type="text/html" id="VerifyDate">
        <input type="checkbox" field="f_vdate" msg="验证日期" value="{{d.cc_id}}" lay-skin="primary"
               lay-filter="ChangeTag" {{ d.f_vdate ? 'checked' : '' }}>
    </script>

</div>
<script language="JavaScript">
    var USER_JWT = "";
    var index = 0;
    var myTable, table, tableindex;
    var c_id = '#(form.key)';

    layui.use(['myTable', 'table', 'form', 'util', 'myTool'], function () {
        var $ = layui.$;
        myTable = layui.myTable, table = layui.table
        form = layui.form, util = layui.util, myTool = layui.myTool;

        tableindex = myTable.render({
            elem: '#table_1'
            , url: 'SysCodeColumnListDataApi'
            , toolbar: '#table_1_bar_title'
            , title: '表单代码生成表'
            , height: 'full-2'
            , where: {orderby: 'f_show desc,f_sindex', c_id: c_id}
            , cols: [[
                {type: 'checkbox'}
                , {field: 'cc_id', title: 'ID', width: 36, align: 'center'}
                , {field: 'cc_name', title: '字段', width: 80}
                , {field: 'cc_title', title: '字段名', width: 80, edit: 'text'}
                , {field: 'f_hidden', title: '隐藏', width: 36, align: 'center', templet: '#TmpHidden'}
                , {field: 'f_show', title: '列显', width: 36, align: 'center', templet: '#TmpShow'}
                , {field: 'f_sindex', title: '行数', width: 45, align: 'center', edit: 'text'}
                , {field: 'f_width', title: '行宽', width: 70, align: 'center', edit: 'text'}
                , {field: 'cc_type', title: '类型', width: 70}
                , {field: 'is_key', title: '主键', width: 36, align: 'center', templet: '#TmpKey'}
                , {field: 'f_auto', title: '自增', width: 36, align: 'center', templet: '#EditAuto'}
                , {field: 'f_readonly', title: '只读', width: 36, align: 'center', templet: '#EditReadonly'}
                , {field: 'f_select', title: '选择', width: 36, align: 'center', templet: '#EditSelect'}
                , {field: 'f_switch', title: '开关', width: 36, align: 'center', templet: '#EditSwitch'}
                , {field: 'f_img', title: '图', width: 36, align: 'center', templet: '#EditImg'}
                , {field: 'f_number', title: '数字', width: 36, align: 'center', templet: '#EditNumber'}
                , {field: 'f_icon', title: '图标', width: 36, align: 'center', templet: '#EditIcon'}
                , {field: 'f_color', title: '选色', width: 36, align: 'center', templet: '#EditColor'}
                , {field: 'f_date', title: '日期', width: 36, align: 'center', templet: '#EditDate'}
                , {field: 'f_more', title: '多行', width: 36, align: 'center', templet: '#EditMore'}
                , {field: 'f_vnull', title: '验空', width: 36, align: 'center', templet: '#VerifyNull'}
                , {field: 'f_vnumber', title: '验数字', width: 50, align: 'center', templet: '#VerifyNumber'}
                , {field: 'f_vemail', title: '验邮箱', width: 50, align: 'center', templet: '#VerifyEmail'}
                , {field: 'f_vdate', title: '验日期', width: 50, align: 'center', templet: '#VerifyDate'}
                , {field: 'f_vmsg', title: '验证提示', width: 120, align: 'left', edit: 'text'}
            ]]
            , page: true, limit: 10
            , serviceSort: true, initSort: {field: 'f_sindex', type: 'asc'}
            , editField: {url: 'ModifySysCodeColumnFieldApi', key: 'cc_id'}
        });
        //头工具栏事件
        table.on('toolbar(table_1)', function (obj) {
            myTool.toolbar(this, obj, {
                ReloadCodeColumn: function () {
                    tableindex.reload();
                }
                , CloseCodeColumn: function () {
                    parent.layer.closeAll();
                }
                , InitSysCodeColumn: function () {
                    index = layer.confirm('你是否确认初始化表字段', {icon: 3, title: '提示', offset: '100px'}, function (index2) {
                        layer.close(index2);
                        layer.load();
                        $.get("InitSysCodeColumn", {c_id: c_id}, function (result) {
                            layer.close("loading");
                            if (result.code == 0) {
                                layer.msg(result.msg);
                                tableindex.reload();
                            } else {
                                layer.msg(result.msg);
                            }
                        });
                    });
                }
                , DelSysCodeColumn: function () {
                    myTool.doMoreSelect(table.checkStatus('table_1'), {key: 'cc_id'}, function (data, keys) {
                        index = layer.confirm('你是否确认删除选中的【' + data.length + '】记录', {icon: 3, title: '提示', offset: '100px'}, function (index2) {
                            layer.close(index2);
                            myTool.post("DelSysCodeColumnApi", {keys: keys}, function () {
                                tableindex.reload();
                            });
                        });
                    })
                }
                , SysCodeColumnColumn: function () {
                    myTool.doSingleSelect(table.checkStatus('table_1'), {}, function (data, keys) {
                        index = layer.open({
                            type: 2, offset: '10px', area: ['900px', '550px'],
                            title: ['字段配置[' + data[0].table_name + ']', 'font-size:15px;'],
                            content: ["SysCodeColumnColumnList?c_id=" + data[0].c_id, 'no'],
                            end: function () {
                                tableindex.reload({});
                            }
                        });
                    })
                }
            })
        });

        //监听单元格编辑
        form.on('checkbox(ChangeTag)', function (obj) {
            myTool.postMsg("ChangeSysCodeColumnApi", {cc_id: this.value, field: $(obj.elem).attr("field"), msg: $(obj.elem).attr("msg")}, function (result) {
                layer.tips(result.msg, obj.othis);
            });
        });
    });
</script>
#include("../../comm/Foot.html")